import { Message } from "element-ui";

let messageInstance = null;
function singleMessage(options) {
  if (messageInstance) {
    messageInstance.close();
  }
  if (typeof options === "string") {
    messageInstance = Message(options);
  }else{
    messageInstance = Message[options.type](options);
  }
}
["success", "warning", "info", "error"].forEach(type => {
  singleMessage[type] = options => {
    if (typeof options === "string") {
      options = {
        message: options
      };
    }
    options.type = type;
    if (messageInstance) {
      messageInstance.close();
    }
    messageInstance = Message[type](options);
  };
});
export default singleMessage;
